package chunithmlauncher;

import chunithmlauncher.option.ChunithmOption;
import chunithmlauncher.utils.JsonUtil;
import de.felixroske.jfxsupport.FXMLController;
import javafx.event.Event;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.TextField;
import javafx.stage.FileChooser;
import javafx.stage.Stage;

import java.io.File;
import java.net.URL;
import java.util.ResourceBundle;

@FXMLController
public class ToolController implements Initializable {
    @FXML
    private TextField startbat;

    @FXML
    private TextField segatool;



    void initialize() {}
    void initData(String path) {
        startbat.setText(path);
    }
    @FXML
    public void selectStartBat(final Event e) {
        FileChooser fileChooser = new FileChooser();
        fileChooser.setTitle("请选择游戏启动文件");
        fileChooser.getExtensionFilters().addAll( new FileChooser.ExtensionFilter("请选择start.bat", "*start.bat"));
        File file = fileChooser.showOpenDialog(new Stage());
        String path=file.getPath();
        MainController.chunithmOption.setStartbat(path);
        startbat.setText(path);
        JsonUtil.object2JsonFile(ToolController.class.getClassLoader().getResource("config.json").getPath(),MainController.chunithmOption);
    }

    @FXML
    public void selectSegaTools(final Event e) {
        FileChooser fileChooser = new FileChooser();
        fileChooser.setTitle("请选择segatools文件");
        fileChooser.getExtensionFilters().addAll(new FileChooser.ExtensionFilter("请选择segatools.ini","*segatools.ini"));
        File file = fileChooser.showOpenDialog(new Stage());
        String path = file.getPath();
        MainController.chunithmOption.setSegatools(path);
        JsonUtil.object2JsonFile(ToolController.class.getClassLoader().getResource("config.json").getPath(),MainController.chunithmOption);
        segatool.setText(path);

    }

    @Override
    public void initialize(URL location, ResourceBundle resources) {

    }
}